﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
namespace Entity
{
    public class GIAOVIEN
    {
        private String MAGV, TENGV, GIOITINH, DIACHI, QUEQUAN, MAHOCVI, MAKHOA;
        private float HESOLUONG, MUCLUONG;
        private DateTime NGAYSINH, NGBDL;

        public String maGV
        {
            get { return MAGV; }
            set { MAGV = value; }
        }

        public String tenGV
        {
            get { return TENGV; }
            set { TENGV = value; }
        }

        public String gioitinh
        {
            get { return GIOITINH; }
            set { GIOITINH = value; }
        }

        public String diachi
        {
            get { return DIACHI; }
            set { DIACHI = value; }
        }

        public String quequan
        {
            get { return QUEQUAN; }
            set { QUEQUAN = value; }
        }

        public String maHocvi
        {
            get { return MAHOCVI; }
            set { MAHOCVI = value; }
        }


        public String maKhoa
        {
            get { return MAKHOA; }
            set { MAKHOA = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public float hesoluong
        {
            get { return HESOLUONG; }
            set { HESOLUONG = value; }
        }

        public float mucluong
        {
            get { return MUCLUONG ; }
            set { MUCLUONG = value; }
        }
        /// <summary>
        /// 
        /// </summary>

        public DateTime ngaysinh
        {
            get { return NGAYSINH; }
            set { NGAYSINH = value; }
        }

        public DateTime ngBDL
        {
            get { return NGBDL; }
            set { NGBDL = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public void them_GiaoVien(GIAOVIEN giaovien)
        {
            String excuteString = "INSERT INTO GIAOVIEN VALUES('" + giaovien.maGV + "','"
                                                           + giaovien.tenGV + "','"
                                                           + giaovien.gioitinh + "','"
                                                           + giaovien.ngaysinh + "','"
                                                           + giaovien.diachi + "','"
                                                           + giaovien.quequan + "','"
                                                           + giaovien.NGBDL + "','"
                                                           + giaovien.maHocvi + "',"
                                                           + giaovien.hesoluong + ","
                                                           + giaovien.mucluong + ",'"
                                                           + giaovien.maKhoa + "')" ;
            
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void sua_GiaoVien(GIAOVIEN giaovien)
        {
            String excuteString = "UPDATE GIAOVIEN SET TENGV ='" + giaovien.tenGV +
                                                "',GIOITINH ='" + giaovien.gioitinh +
                                                "',NGAYSINH ='" + giaovien.ngaysinh +
                                                "',DIACHI ='" + giaovien.diachi +
                                                "',QUEQUAN ='" + giaovien.quequan +
                                                "',NGBDVL='" + giaovien.NGBDL + 
                                                "',MAHOCVI = '" + giaovien.maHocvi +
                                                "',HESOLUONG =" + giaovien.hesoluong +
                                                ",MUCLUONG=" + giaovien.mucluong +
                                                "WHERE MAGV ='" + giaovien.maGV + "'";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void xoa_GiaoVien(String magv)
        {
            String excuteString1 = "DELETE FROM BANGLUONGCB WHERE MAGV ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString1);

            String excuteString2 = "DELETE FROM BANGLUONGKN WHERE MAGV ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString2);

            String excuteString3 = "DELETE FROM BANGLUONGGD WHERE MAGV ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString3);

            String excuteString4 = "DELETE FROM CV_GIAOVIEN WHERE MAGV ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString4);

            String excuteString5 = "DELETE FROM DETAI WHERE MAGVHD ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString5);

            String excuteString6 = "DELETE FROM GIANGDAY WHERE MAGV ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString6);

            String excuteString7 = "DELETE FROM NX_DETAI WHERE MAGVNX ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString7);

            String excuteString9 = "DELETE FROM LOPHOC  WHERE MAGVCN ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString9);

            String excuteString = "DELETE FROM GIAOVIEN WHERE MAGV ='" + magv + "'";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void hienthi_GiaoVien(DataGridView dtgGiaoVien)
        {
            DataTable dataTable = new DataTable();
            dataTable = dataBaseAccess.getDataTable("SELECT * FROM GIAOVIEN");
            dtgGiaoVien.DataSource = dataTable;
        }
    }
}
